/**
 * @用爱埃拉托色尼筛网法求质数,这个爱埃拉托色尼筛网法求质数怎么做？
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>
#define COUNT 3000

int main(int argc, char *argv[]) {
	int numbers[COUNT+1];	// p

	//初始化数组全是0
	for (int i=2; i<=COUNT; i++) { 
		numbers[i] = 0;
	}

	// algorithm
	for (int i=2; i<=COUNT; i++) {
		for (int j=2; i*j<=COUNT; j++) {
			numbers[i*j] = 1;
		}
	}

	// print prime numbers
	for (int i=1; i<=COUNT; i++) {
		if (numbers[i] == 0) {
			printf("%d ", i);
		}
	}

	printf("\n");

	return 0;
}

